// pages/collect/collect.js
import { getCollectGoods } from '../../service/public'
const obj = {
	gid: 38,
	g_longImg:
		'https://img30.360buyimg.com/cf/jfs/t1/132280/9/2582/56380/5eec71deEa6e88bbc/431e493b152f4a31.jpg',
	g_name: '科大讯飞OS语音车载充电器',
	g_start_money: 4398,
	g_end_money: 6479,
	followers_num: 85,
	pro: 67,
}

Page({
	data: {
		titles: ['关注的项目', '浏览足迹'],
    goodsList: [],
    activeIndex:0
  },
  allGoods:[],
	onLoad(options) {

    this._getCollectGoods()
    
    this.setData({
      activeIndex:parseInt(options.type) || 0
    })
	},
	// 获得商品信息
	_getCollectGoods() {
		getCollectGoods().then((res) => {
      this.allGoods = res.data.data
      this._filterList(this.allGoods[this.data.activeIndex])
		})
  },
  _filterList(arr){
    arr.forEach(v=>{
      let sNum = v.g_start_money
      let eNum = v.g_end_money
      let progress = parseInt((sNum / eNum) * 100)
      v.pro =  isNaN(progress) ? 0 : progress >100 ? 100 : progress
    })
    this.setData({
      goodsList:arr
    })

  },
  changeNav(e){
    const {index} = e.detail

    
    this._filterList(this.allGoods[index])

  }
})
